﻿Public Class DtpoUsoInmueble

    Public Shared Function SeleccionarTodo(ByVal descEmpresa As String) As List(Of EtpoUsoInmueble)
        Dim tpoUsoInmuebles As List(Of EtpoUsoInmueble) = Nothing 'Es una coleccion de lista tipado (vendedor)

        Using cn As New SqlConnection(ConfigurationManager.ConnectionStrings(descEmpresa).ConnectionString)
            Using cmd As New SqlCommand("usp_tpoUsoInmueble_sel", cn)
                cmd.CommandType = CommandType.StoredProcedure
                Try
                    cn.Open()
                    Using dr As SqlDataReader = cmd.ExecuteReader(CommandBehavior.SingleResult Or CommandBehavior.CloseConnection)
                        If dr.HasRows Then
                            tpoUsoInmuebles = New List(Of EtpoUsoInmueble)
                            Dim tpoUsoInmueble As EtpoUsoInmueble = Nothing 'tipo 
                            Do While dr.Read
                                tpoUsoInmueble = New EtpoUsoInmueble( _
                                    dr.GetInt32(dr.GetOrdinal("idTpoUsoInmueble")), _
                                    dr.GetString(dr.GetOrdinal("desctpoUsoInmueble")), _
                                    dr.GetString(dr.GetOrdinal("estado")), _
                                    dr.GetInt32(dr.GetOrdinal("idUsuario")))
                                tpoUsoInmuebles.Add(tpoUsoInmueble)
                            Loop
                            dr.Close()
                        End If
                    End Using
                Catch ex As Exception
                    Throw
                End Try
            End Using
        End Using

        Return tpoUsoInmuebles
    End Function
    Public Shared Function SeleccionarXEstado(ByVal descEmpresa As String) As List(Of EtpoUsoInmueble)
        Dim tpoUsoInmuebles As List(Of EtpoUsoInmueble) = Nothing 'Es una coleccion de lista tipado (vendedor)

        Using cn As New SqlConnection(ConfigurationManager.ConnectionStrings(descEmpresa).ConnectionString)
            Using cmd As New SqlCommand("usp_tpoUsoInmueble_selXEstado", cn)
                cmd.CommandType = CommandType.StoredProcedure
                Try
                    cn.Open()
                    Using dr As SqlDataReader = cmd.ExecuteReader(CommandBehavior.SingleResult Or CommandBehavior.CloseConnection)
                        If dr.HasRows Then
                            tpoUsoInmuebles = New List(Of EtpoUsoInmueble)
                            Dim tpoUsoInmueble As EtpoUsoInmueble = Nothing 'tipo 
                            Do While dr.Read
                                tpoUsoInmueble = New EtpoUsoInmueble( _
                                    dr.GetInt32(dr.GetOrdinal("idTpoUsoInmueble")), _
                                    dr.GetString(dr.GetOrdinal("desctpoUsoInmueble")), _
                                    dr.GetString(dr.GetOrdinal("estado")), _
                                    dr.GetInt32(dr.GetOrdinal("idUsuario")))
                                tpoUsoInmuebles.Add(tpoUsoInmueble)
                            Loop
                            dr.Close()
                        End If
                    End Using
                Catch ex As Exception
                    Throw
                End Try
            End Using
        End Using

        Return tpoUsoInmuebles
    End Function
    Public Shared Function Añadir(ByVal descEmpresa As String, ByVal tpoUsoInmueble As EtpoUsoInmueble) As Boolean
        Dim resultado As Boolean = False

        Using cn As New SqlConnection(ConfigurationManager.ConnectionStrings(descEmpresa).ConnectionString)
            Using cmd As New SqlCommand("usp_tpoUsoInmueble_add", cn)
                cmd.CommandType = CommandType.StoredProcedure
                cmd.Parameters.Add("@desctpoUsoInmueble", SqlDbType.VarChar, 55).Value = tpoUsoInmueble.descTpoUsoInmueble
                cmd.Parameters.Add("@idUsuario", SqlDbType.Int).Value = tpoUsoInmueble.idUsuario
                Try
                    cn.Open()
                    cmd.ExecuteNonQuery()
                    resultado = True
                Catch ex As Exception
                    Throw
                End Try
            End Using
        End Using

        Return resultado
    End Function
    Public Shared Function Editar(ByVal descEmpresa As String, ByVal tpoUsoInmueble As EtpoUsoInmueble) As Boolean
        Dim resultado As Boolean = False

        Using cn As New SqlConnection(ConfigurationManager.ConnectionStrings(descEmpresa).ConnectionString)
            Using cmd As New SqlCommand("usp_tpoUsoInmueble_edit", cn)
                cmd.CommandType = CommandType.StoredProcedure
                cmd.Parameters.Add("@idTpoUsoInmueble", SqlDbType.Int).Value = tpoUsoInmueble.idTpoUsoInmueble
                cmd.Parameters.Add("@desctpoUsoInmueble", SqlDbType.VarChar, 55).Value = tpoUsoInmueble.descTpoUsoInmueble
                cmd.Parameters.Add("@estado", SqlDbType.Char, 1).Value = tpoUsoInmueble.estado
                cmd.Parameters.Add("@idUsuario", SqlDbType.Int).Value = tpoUsoInmueble.idUsuario
                Try
                    cn.Open()
                    cmd.ExecuteNonQuery()
                    resultado = True
                Catch ex As Exception
                    Throw
                End Try
            End Using
        End Using

        Return resultado
    End Function
    Public Shared Function Eliminar(ByVal descEmpresa As String, ByVal tpoUsoInmueble As EtpoUsoInmueble) As Boolean
        Dim resultado As Boolean = False

        Using cn As New SqlConnection(ConfigurationManager.ConnectionStrings(descEmpresa).ConnectionString)
            Using cmd As New SqlCommand("usp_tpoUsoInmueble_del", cn)
                cmd.CommandType = CommandType.StoredProcedure
                cmd.Parameters.Add("@idTpoUsoInmueble", SqlDbType.Int).Value = tpoUsoInmueble.idTpoUsoInmueble
                cmd.Parameters.Add("@idUsuario", SqlDbType.Int).Value = tpoUsoInmueble.idUsuario
                Try
                    cn.Open()
                    cmd.ExecuteNonQuery()
                    resultado = True
                Catch ex As Exception
                    Throw
                End Try
            End Using
        End Using

        Return resultado
    End Function

End Class
